unit FormPesquisaFuncionarioUnit;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Actions, Vcl.ActnList, Vcl.Grids,
  Vcl.DBGrids, JvExDBGrids, JvDBGrid, Vcl.StdCtrls;

type
  TFormPesquisaFuncionario = class(TForm)
    Label1: TLabel;
    EditPesquisa: TEdit;
    JvDBGrid1: TJvDBGrid;
    ActionList1: TActionList;
    ActionESC: TAction;
    procedure ActionESCExecute(Sender: TObject);
    procedure EditPesquisaChange(Sender: TObject);
    procedure EditPesquisaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure JvDBGrid1DblClick(Sender: TObject);
    procedure JvDBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
    idfuncionario : integer;
    nomefuncionario : string;
  end;

var
  FormPesquisaFuncionario: TFormPesquisaFuncionario;

implementation

{$R *.dfm}

uses DMDadosUnt;

procedure TFormPesquisaFuncionario.ActionESCExecute(Sender: TObject);
begin
  idfuncionario   := 0;
  nomefuncionario := '';
  close;
end;

procedure TFormPesquisaFuncionario.EditPesquisaChange(Sender: TObject);
begin
  DMDados.dsCadastroFuncionario.DataSet.Filtered := false;

  DMDados.dsCadastroFuncionario.DataSet.Filter := 'NOME_FUNCIONARIO LIKE '+QuotedStr('%'+EditPesquisa.Text+'%')+
                                           ' OR CPF LIKE'+QuotedStr('%'+EditPesquisa.Text+'%');

  DMDados.dsCadastroFuncionario.DataSet.Filtered := true;
end;

procedure TFormPesquisaFuncionario.EditPesquisaKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
if key = VK_DOWN then
begin
  JvDBGrid1.SetFocus;
end;
if key = VK_RETURN then
begin
  JvDBGrid1.SetFocus;
end;
end;

procedure TFormPesquisaFuncionario.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  DMDados.dsCadastroFuncionario.DataSet.Filtered := False;
end;

procedure TFormPesquisaFuncionario.FormCreate(Sender: TObject);
begin
  DMDados.cdsCadastroFuncionario.Open;
end;

procedure TFormPesquisaFuncionario.JvDBGrid1DblClick(Sender: TObject);
begin
  idfuncionario   := DMDados.cdsCadastroFuncionarioID_FUNCIONARIO.AsInteger;
  nomefuncionario := DMDados.cdsCadastroFuncionarioNOME_FUNCIONARIO.AsString;
  Close;
end;

procedure TFormPesquisaFuncionario.JvDBGrid1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key = VK_RETURN then
  begin

    idfuncionario   := DMDados.cdsCadastroFuncionarioID_FUNCIONARIO.AsInteger;
    nomefuncionario := DMDados.cdsCadastroFuncionarioNOME_FUNCIONARIO.AsString;
    Close;


  end;
end;

end.
